package aar.test.tessocr.adapter;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.RadioButton;
import android.widget.TextView;

import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import aar.test.tessocr.CabinetDetailsActivity;
import aar.test.tessocr.SiteDispatchActivity;
import aar.test.tessocr.baseApplication.BaseApplication;
import aar.test.tessocr.model.CabinetListMpdel;
import aar.test.tessocr.model.CompanySearchModel;
import aar.test.tessocr.model.DialogCallback;
import aar.test.tessocr.model.LzyResponse;
import aar.test.tessocr.model.UnexporderListModel;
import aar.test.tessocr.utils.Urls;
import clx.tessocr.ocreng.R;
import okgo.OkGo;
import okgo.model.Response;
import okhttp3.RequestBody;

import static aar.test.tessocr.Login1Activity.JSON;

/**
 * Created by 149-201605 on 2016/8/1.
 */

/*
 * 主界面显示 dialog的资源适配器
 * */
public class UnexporderListAdapter extends BaseAdapter {

    private List<UnexporderListModel> mList;

    private Context mContext;


    public UnexporderListAdapter(Context mContext, List<UnexporderListModel> mList) {
        this.mList = mList;
        this.mContext = mContext;


    }


    @Override
    public int getCount() {
        int count = 0;
        if (null != mList && !mList.isEmpty()) {
            count = mList.size();
        }
        return count;
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder showDialogHolder = null;
        if (null == convertView) {
            showDialogHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.unexporder_list_item, null);

            showDialogHolder.express_order = (TextView) convertView.findViewById(R.id.express_order);
            showDialogHolder.order_phone = (TextView) convertView.findViewById(R.id.order_phone);
            showDialogHolder.title_details = (TextView) convertView.findViewById(R.id.title_details);
            showDialogHolder.order_grid_open = (TextView) convertView.findViewById(R.id.order_grid_open);
            showDialogHolder.order_com = (TextView) convertView.findViewById(R.id.order_com);
            showDialogHolder.grid_small = (RadioButton) convertView.findViewById(R.id.grid_small);
            showDialogHolder.grid_middle = (RadioButton) convertView.findViewById(R.id.grid_middle);
            showDialogHolder.grid_big = (RadioButton) convertView.findViewById(R.id.grid_big);



            convertView.setTag(showDialogHolder);
        } else {
            showDialogHolder = (ViewHolder) convertView.getTag();
        }



        if(!TextUtils.isEmpty(mList.get(position).getExpress_order())){
            showDialogHolder.express_order.setText(mList.get(position).getExpress_order());
        }


        if(!TextUtils.isEmpty(mList.get(position).getPhone())){
            showDialogHolder.order_phone.setText(mList.get(position).getPhone());
        }

       final int pos=position;

        String detail="您有一份XXXX快递，运单号"+mList.get(position)
                .getExpress_order()+"已存入"+"的快递柜，取件码XXXXXX，请尽快领取";

        showDialogHolder.title_details.setText(detail);


        showDialogHolder.order_grid_open.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

     if(null!=mViewClickListener){
         mViewClickListener.gridopen(pos);
     }

            }
        });


        showDialogHolder.order_com.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if(null!=mViewClickListener){
                    mViewClickListener.gridconfire(pos);
                }


            }
        });



        if(TextUtils.equals(mList.get(position).getGridType(),"1")){
            showDialogHolder.grid_middle.setChecked(true);
        }else  if(TextUtils.equals(mList.get(position).getGridType(),"2")){
            showDialogHolder.grid_big.setChecked(true);

        }else  if(TextUtils.equals(mList.get(position).getGridType(),"3")){
            showDialogHolder.grid_small.setChecked(true);
        }



        return convertView;
    }


    class ViewHolder {

        TextView express_order;
        TextView order_phone;
        RadioButton grid_small;
        RadioButton grid_middle;
        RadioButton grid_big;
        TextView title_details;
        TextView order_grid_open;
        TextView order_com;
    }


    public interface ViewClickListener{
        void gridopen(int pos);
        void gridconfire(int pos);
    }

    public void setViewClickListener(ViewClickListener mViewClickListener){
        this.mViewClickListener=mViewClickListener;

    }


    private ViewClickListener mViewClickListener;



}


